#Alexander F. Gazmararian
#afg2@princeton.edu

library(tidyverse)
library(modelsummary)
library(margins)
library(kableExtra)
library(sandwich)

#load functions/themes
source("code/fun/book_theme.R")
source("code/fun/savefig.R")
source("code/fun/fix_txt.R")

#load data
g <- readRDS("data/NatQual_August22.rds")

#customize coefficient names
source("code/fun/coefnames4tables.R")

#specify base model
f.base <- y ~ age + Female + Black + Hispanic + income5 + CollegeDegree + PartySummary + employfull + green_index + gw_index + trustfed_Scale

# Correlation between trust and credibility for online appendix

#specify model
f.local <- update(f.base, CommitLoc_Scale ~ . - green_index - age + scale(age))

models.local <- list()
models.local[[1]]<-lm(update(f.local, CommitLoc_Scale ~ . - income5 + HighIncome), g)
models.local[[2]]<-lm(f.local, g)
models.local[[3]]<-lm(update(f.local, ~ . + green_index), g)

# Create table
file <- "tables/ch3/fedcommit2localmitigate.txt"
modelsummary(
  models.local,
  coef_map = coefnames,
  vcov = "HC2",
  stars = c("*"=.1,"**"=0.05,"***"=.01),
  gof_map = c("nobs", "adj.r.squared"),
  escape=FALSE,
  output = "latex"
) %>%
  cat(., file = file)
fix_txt(file)
